package com.lh.tams.service.system;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.lh.tams.dao.system.LawMaxDao;
import com.lh.tams.dao.system.LawMinDao;
import com.lh.tams.domain.TamsMaxLaw;
import com.lh.tams.domain.TamsMinLaw;
import com.lh.tams.domain.TamsPerson;
import com.lh.tams.exception.BusinessException;
import com.lh.tams.util.DataGridModel;
import com.lh.tams.util.Page;

/**
 * 大类Service
 * @author liulin
 * @version 2012-05-18
 */
@Service
public class LawMaxService {
	private LawMaxDao lawMaxDao;
	private LawMinDao lawMinDao;
	
	public LawMinDao getLawMinDao() {
		return lawMinDao;
	}

	public void setLawMinDao(LawMinDao lawMinDao) {
		this.lawMinDao = lawMinDao;
	}

	public LawMaxDao getLawMaxDao() {
		return lawMaxDao;
	}

	public void setLawMaxDao(LawMaxDao lawMaxDao) {
		this.lawMaxDao = lawMaxDao;
	}

	public Page query(DataGridModel dgm,TamsMaxLaw tamsMaxLaw){
		return lawMaxDao.query(dgm, tamsMaxLaw);
	}
	
	public void add(TamsMaxLaw tamsMaxLaw){
		lawMaxDao.add(tamsMaxLaw);
	}
	
	public void update(TamsMaxLaw tamsMaxLaw){
		lawMaxDao.update(tamsMaxLaw);
	}
	
	public void delete(long[] ids){
		
		//查询大类下小类
		List<TamsMinLaw> list= new ArrayList<TamsMinLaw>();
		for (int i = 0; i < ids.length; i++) {
			List<TamsMinLaw> l = lawMinDao.queryPersonIdByMax(ids[i]);
			list.addAll(l);
		}
		if(list.size()>0){
			throw new BusinessException("大类下存在小类，请先删除该小类!");
		}
		
		lawMaxDao.delete(ids);
	}
}
